package com.csu.ui;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.*;

public class UserPanel extends JPanel {
	
	//用户名
	private String currAcct;
	
	public String getCurrAcct() {
		return currAcct;
	}

	public void setCurrAcct(String currAcct) {
		this.currAcct = currAcct;
	}

	ImageIcon helpImg = new ImageIcon("photo/help.png");

	private JLabel welcomeLabel = new JLabel();
	private JLabel serviceLabel = new JLabel("请选择您的服务：");
	private JLabel helpLabel = new JLabel(helpImg);
	private JButton changePwdBtn = new JButton("修改密码");
	private JButton selectBtn = new JButton("查询用户");
	private JButton addBtn = new JButton("添加用户");
	private JButton deleteBtn = new JButton("删除用户");
	private JButton changeBtn = new JButton("更改用户");
	private UserSecPanel secPanel = new UserSecPanel();
	
	public void setAllFalse() {
		secPanel.allFalse();
	}
	
	public void setLabelText(String str) {
		welcomeLabel.setText(str);
	}
	
	public void setBtnUnable() {
		selectBtn.setEnabled(false);
		addBtn.setEnabled(false);
		deleteBtn.setEnabled(false);
		changeBtn.setEnabled(false);
	}
	
	public void setBtnAble() {
		selectBtn.setEnabled(true);
		addBtn.setEnabled(true);
		deleteBtn.setEnabled(true);
		changeBtn.setEnabled(true);
	}
	
	UserPanel(){
		
		setLayout(null);
		welcomeLabel.setBounds(50, 50, 100, 50);
		this.add(welcomeLabel);
		serviceLabel.setBounds(50, 150, 100, 50);
		this.add(serviceLabel);
		helpLabel.setBounds(150,160,25,25);
		this.add(helpLabel);
		helpLabel.addMouseListener(new MouseListener() {
			@Override
			public void mouseClicked(MouseEvent e) {
				secPanel.allFalse();
			}

			@Override
			public void mousePressed(MouseEvent e) {

			}

			@Override
			public void mouseReleased(MouseEvent e) {

			}

			@Override
			public void mouseEntered(MouseEvent e) {

			}

			@Override
			public void mouseExited(MouseEvent e) {

			}
		});
		
		changePwdBtn.setBounds(50, 250, 100, 50);
		this.add(changePwdBtn);
		changePwdBtn.addActionListener(new ActionListener() {	
			@Override
			public void actionPerformed(ActionEvent e) {
				secPanel.setCurrAcct(currAcct);
				secPanel.orgPwdField.setText("");
				secPanel.newPwdField.setText("");
				secPanel.changePwdPanelTrue();
			}
		});
		
		selectBtn.setBounds(50, 350, 100, 50);
		this.add(selectBtn);
		selectBtn.addActionListener(new ActionListener() {	
			@Override
			public void actionPerformed(ActionEvent e) {
				secPanel.backBtnFalse();
				secPanel.selectUserField.setText("");
				secPanel.selectTypeBox.setSelectedItem("普通用户");
				secPanel.tablePanel.initData();
				secPanel.tablePanel.setCurrPage(1);
				secPanel.tablePanel.setLabel2();
				secPanel.tablePanel.setLabel3();
				secPanel.tablePanel.setBtn();
				secPanel.selectPanelTrue();
			}
		});
		
		addBtn.setBounds(50, 450, 100, 50);
		this.add(addBtn);
		addBtn.addActionListener(new ActionListener() {	
			@Override
			public void actionPerformed(ActionEvent e) {
				secPanel.acctField.setText("");
				secPanel.pwdField.setText("");
				secPanel.typeBox.setSelectedItem("普通用户");
				secPanel.addPanelTrue();
			}
		});
		
		deleteBtn.setBounds(50, 550, 100, 50);
		this.add(deleteBtn);
		deleteBtn.addActionListener(new ActionListener() {	
			@Override
			public void actionPerformed(ActionEvent e) {
				secPanel.delField.setText("");
				secPanel.deletePanelTrue();
			}
		});
		
		changeBtn.setBounds(50, 650, 100, 50);
		this.add(changeBtn);
		changeBtn.addActionListener(new ActionListener() {	
			@Override
			public void actionPerformed(ActionEvent e) {
				secPanel.orgAcctField.setText("");
				secPanel.newAcctField.setText("");
				secPanel.newTypeBox.setSelectedItem("普通用户");
				secPanel.changePanelTrue();
			}
		});
		
		secPanel.setBounds(200, 75, 800, 625);
		this.add(secPanel);
		
	}
	
}
